<?php

class Model_User extends Mongo_Document
{

	protected $name = 'users';

	/**
	 * set password
	 * @param string $string
	 * @return Model_User
	 *
	 */
	public function setPassword($string)
	{
		$this -> salt = Text::random(8);
		$this -> password = $this -> _createPassword($string, $this -> salt);
		return $this;
	}

	/**
	 * @return bool
	 * is valid password
	 */
	public function isPassword($string)
	{
        return $this -> _createPassword($string, $this -> salt) == $this -> password;
        
	}

	protected function _createPassword($string, $salt)
	{
		return sha1($string . $salt, false);
	}

	

}
